#include <stdlib.h>
#include "ref_ptr.h"

using namespace nbds;

class test {
public:
	int a;
	static bool exist;
	static bool has_existed;
	test() {
		if (exist)
			exit(1);

		exist = true;
		has_existed = true;
	}

	~test() {
		if (!exist)
			exit(1);

		exist = false;
	}
};

bool test::exist;
bool test::has_existed;

ref_ptr<test> *c;

void test2(ref_ptr<test> x) {
	ref_ptr<test> a = x;
	c = new ref_ptr<test>(a);
}

void test1() {
	ref_ptr<test> a(new test);
	ref_ptr<test> b = a;
	test2(b);
}


int main() {
	test::exist = false;
	test::has_existed = false;

	test1();
	delete c;

	if (test::exist)
		exit(1);
	if (!test::has_existed)
		exit(1);
}
